package top.zhangjianyong.tools.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import top.zhangjianyong.tools.service.api.TorrentService;
import top.zhangjianyong.tools.user.VerifyUser;
import top.zhangjianyong.tools.utils.ApiResponse;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/22 2:20 PM
 */
@VerifyUser(login = false)
@RestController
@RequestMapping("/torrent")
public class TorrentController {

    @Autowired
    private TorrentService torrentService;

    @PostMapping(path = "/magnet")
    public ApiResponse torrentToMagnet(@RequestParam("file") MultipartFile torrentFile) throws IOException, NoSuchAlgorithmException {
        return torrentService.torrentToMagnet(torrentFile);
    }

    @PostMapping(path = "/list")
    public ApiResponse list() throws IOException, NoSuchAlgorithmException {
        return torrentService.list();
    }
}
